<?php

	session_start();
	require_once('../config.php');
	include_once("../database/DataBase.php");
	include_once("function.php");

	$company_code = $_POST["company_code"];
	$company_name = $_POST["company_name"];
	$company_desc = $_POST["company_desc"];
	$email = $_POST["email"];
	$phone_no = $_POST["phone_no"];
	$address = $_POST["address"];
	$location = $_POST["location"];
	$area_id = $_POST["location"];
	$category = $_POST["category"];
	$num_language = $_POST["num_language"];
	
	$database = New DataBase();
	$database->open_connection();
	$result = $database->addNewCompany($company_code,$company_name,$company_desc,$email,$phone_no,$address,$location,$category,$num_language);
	
	$cid = $result;
	
	$uploads_dir = "../files/".$cid."/";
	If(!file_exists($uploads_dir)){
		mkdir($uploads_dir);
	}

	if ($_FILES['logo']['name'] > '') { 
		$new_location	="";
		$new_file_name	=$cid."".date("YmdHis").rand().".".substr(strrchr($_FILES['logo']['name'],'.'),1);
		$tmp			=$_FILES['logo']['tmp_name'];
		$new_location	=$uploads_dir.$new_file_name;
		$p_image[$i]	=$new_location;

		copy($tmp,$new_location);
		
		$database->updateCompanyLogo($cid, $new_location);
	}
	
	if($cid > 0){
		$database->LogAction($_SESSION["login_id"], "Add", "Add new Company from ".getIpAddress());
		echo "true";
	}
	else{
		echo "fail";
	}
	
	$database->close_connection();
?>